﻿using System;
using System.Windows.Forms;

namespace RaGE
{
    public partial class ClassMaskWindow : Form
    {
        public ClassMaskWindow()
        {
            InitializeComponent();
        }

        private void ChangeDec(object sender, EventArgs e)
        {
            lockCheckBox = true;

            var number = (ushort) Convert.ToInt16(numericUpDown_mask.Value);

            if (number/512 > 0)
            {
                number = (ushort) (number%512);
                checkBox_MY.Checked = true;
            }
            else
                checkBox_MY.Checked = false;

            if (number/256 > 0)
            {
                number = (ushort) (number%256);
                checkBox_SE.Checked = true;
            }
            else
                checkBox_SE.Checked = false;

            if (number/128 > 0)
            {
                number = (ushort) (number%128);
                checkBox_CLE.Checked = true;
            }
            else
                checkBox_CLE.Checked = false;

            if (number/64 > 0)
            {
                number = (ushort) (number%64);
                checkBox_AR.Checked = true;
            }
            else
                checkBox_AR.Checked = false;

            if (number/32 > 0)
            {
                number = (ushort) (number%32);
                checkBox_AS.Checked = true;
            }
            else
                checkBox_AS.Checked = false;

            if (number/16 > 0)
            {
                number = (ushort) (number%16);
                checkBox_BAR.Checked = true;
            }
            else
                checkBox_BAR.Checked = false;

            if (number/8 > 0)
            {
                number = (ushort) (number%8);
                checkBox_VEN.Checked = true;
            }
            else
                checkBox_VEN.Checked = false;

            if (number/4 > 0)
            {
                number = (ushort) (number%4);
                checkBox_PSY.Checked = true;
            }
            else
                checkBox_PSY.Checked = false;

            if (number/2 > 0)
            {
                number = (ushort) (number%2);
                checkBox_WIZ.Checked = true;
            }
            else
                checkBox_WIZ.Checked = false;

            if (number/1 > 0)
            {
                number = (ushort) (number%1);
                checkBox_BM.Checked = true;
            }
            else
                checkBox_BM.Checked = false;

            lockCheckBox = false;
        }

        private void ChangeBin(object sender, EventArgs e)
        {
            if (lockCheckBox) return;

            ushort number = 0;

            if (checkBox_BM.Checked) number += 1;
            if (checkBox_WIZ.Checked) number += 2;
            if (checkBox_PSY.Checked) number += 4;
            if (checkBox_VEN.Checked) number += 8;
            if (checkBox_BAR.Checked) number += 16;
            if (checkBox_AS.Checked) number += 32;
            if (checkBox_AR.Checked) number += 64;
            if (checkBox_CLE.Checked) number += 128;
            if (checkBox_SE.Checked) number += 256;
            if (checkBox_MY.Checked) number += 512;

            numericUpDown_mask.Value = Convert.ToDecimal(number);
        }

        private void ClassMaskCloseClick(object sender, EventArgs e)
        {
            Dispose();
        }
    }
}
